package idv.arthur.Spring;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;

public class JdbcTemplate01 {

	public static void main(String[] args) {

		SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
		dataSource.setDriverClass(com.mysql.jdbc.Driver.class);
		
		String url = "jdbc:mysql://10.144.136.54:3306/sysflow";
		String userName = "dbadmin";
		String password = "mysql";
		
		dataSource.setUrl( url );
		dataSource.setUsername( userName );
		dataSource.setPassword( password );
		
		/*dataSource.setUrl("jdbc:mysql://10.180.22.4:13306/sysflow");
		dataSource.setUsername("devOps");
		dataSource.setPassword("devOps1234");*/
		
		JdbcTemplate jt = new JdbcTemplate(dataSource);

		String sql = "SELECT pageTitle FROM pagelist";

		List<String> results = jt.query(sql, new RowMapper<String>() {
			public String mapRow(ResultSet rs, int rowNum) throws SQLException {
				return new String(rs.getString("pageTitle"));
			}
		});
		
		for(String str:results) {
			System.out.println(str);
		}
		
	}

}
